package service

import (
	"go-ecommerce/config"
	"go-ecommerce/internal/model"
	"golang.org/x/crypto/bcrypt"
)

func Login(username, password string) (*model.Admin, error) {
	var user model.Admin
	if err := config.DB.Where("username = ?", username).First(&user).Error; err != nil {
		return nil, err
	}
	if err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(password)); err != nil {
		return nil, err
	}
	return &user, nil
}
